<?php
require_once("lib/nusoap.php");
require_once("class.request_fetcher.php");
require_once("class.markup_config.php");
require_once("class.markup_configs_helper.php");
error_reporting(0);
$server = new soap_server();
$server->configureWSDL("RequestWSDL","urn:cfgRequest");
$server->wsdl->addComplexType(
"MarkInfo","complexType","struct","all","",
array("MARKUP_INFO"=>array("MARKUP_RULE_ID"=>array("name"=>"MARKUP_RULE_ID","type"=>"xsd:string"))));
$server->wsdl->addComplexType(                                                                                     
'RequestInfo',
'complexType',
'struct',
'all',
'',
array("REQUESTS"=>array('RequestID' => array('name' => 'RequestID', 'type' => 'xsd:string'),'RequestIndex' => array('name' => 'RequestIndex', 'type' => 'xsd:int'),'ConfigID' => array('name' => 'ConfigID', 'type' => 'xsd:string'))));
$server->wsdl->addComplexType(
'RequestArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:RequestInfo[]')
),
'tns:RequestInfo'
);
$server->wsdl->addComplexType(
'MarkupRuleArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:MarkInfo[]')
),
'tns:MarkInfo'
);
  $server->register("RequestService",array("origin"=>"xsd:string","destination"=>"xsd:string"),array("return"=>"tns:RequestArray"),"urn:cfgRequest","urn:cfgRequest#RequestService","rpc","encoded","Service Used for the Starting of request Fetcher");
  $server->register("MarkupService",array("config_id"=>"xsd:string","airline_code"=>"xsd:string","fare_type"=>"xsd:string","trip_type"=>"xsd:string","ptc"=>"xsd:string","cab_cla"=>"xsd:string","sid"=>"xsd:string","price_range"=>"xsd:string","search_time"=>"xsd:string","flight_type"=>"xsd:string"),array("MARKUP"=>"tns:MarkInfo"),"urn:cfgRequest","urn:cfgRequest#MarkupService","rpc","encoded","Service used for computation of markup");
  $server->register("AggrMarkupService",array("config_id"=>"xsd:string"),array("MARKUPS"=>"tns:MarkupRuleArray"),"urn:cfgRequest","urn:cfgRequest#AggrMarkupService","rpc","encoded","Service Used for the Aggregate Markup Fetching");
  
  function RequestService($origin,$destination)
  {   $req_fet= new request_fetcher();
      $req_fet->get_request_index($origin,$destination);
      $arr1=$req_fet->request_arr;
      $arr=array();
      $i=1;
      foreach($arr1 as $ele)
      {
      $arr[]=array("REQUESTS"=>array("RequestID"=>$ele["idRequests"],"RequestIndex"=>$i,"ConfigID"=>$ele["config_id"]));
      $i++;
      }
      return $arr;
  }
  
  function MarkupService($config_id,$airline_code,$fare_type,$trip_type,$ptc,$cab_cla,$sid,$price_range,$search_time,$flight_type)
  {
  $mark_con= new markup_config($config_id,$fare_type,$airline_code,$trip_type,$ptc,$cab_cla,$sid,$price_range,$search_time,$flight_type);
  $mark_con->assign_markup();
  $rule=$mark_con->config_mark[0];
  $elo=markup_configs_helper::get_markup_rule_by_rule_id($rule["rule_id"]);
  return array("MARKUP_INFO"=>array(markup_configs_helper::get_markup_rule_by_rule_id($rule["rule_id"]),$rule));
  }
  
  function AggrMarkupService($config_id)
  {
      $arr=markup_configs_helper::get_markup_by_config($config_id);
      $arr2=array();
      foreach($arr as $ele)
      {
       $arr2[]=array("MARKUP_INFO"=>array("MARKUP_RULE_ID"=>array_merge(markup_configs_helper::get_markup_rule_by_rule_id($ele["rule_id"]),$ele)));   
      }
      return $arr2;
  }
$HTTP_RAW_POST_DATA=isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:"";
$server->service($HTTP_RAW_POST_DATA);
  ?>
